package com.app.service.impl;


import com.app.mapper.TrainTypeConfigMapper;
import com.app.mapper.TrainTypeConfigSonMapper;
import com.app.model.ConfigModel;
import com.app.model.TrainTypeConfigModel;
import com.app.model.TrainTypeConfigSonModel;
import com.app.service.TrainTypeConfigService;
import com.app.service.TrainTypeConfigSonService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TrainTypeConfigSonServiceImpl implements TrainTypeConfigSonService {

    @Resource
    private TrainTypeConfigSonMapper trainTypeConfigSonMapper;


    @Override
    public List<TrainTypeConfigSonModel> getListByTrainId(Integer trainId) {

        QueryWrapper<TrainTypeConfigSonModel> queryWrapper = new QueryWrapper<>();
        if(trainId!=null&&trainId>0)
        {
            queryWrapper.eq("train_id", trainId);

        }
        List<TrainTypeConfigSonModel> conList = trainTypeConfigSonMapper.selectList(queryWrapper);
        return conList;
    }

    @Override
    public List<TrainTypeConfigSonModel> getListByTypeId(Integer typeId) {
        QueryWrapper<TrainTypeConfigSonModel> queryWrapper = new QueryWrapper<>();
        if(typeId!=null&&typeId>0)
        {
            queryWrapper.eq("type_id", typeId);
        }
        List<TrainTypeConfigSonModel> conList = trainTypeConfigSonMapper.selectList(queryWrapper);
        return conList;
    }

    @Override
    public TrainTypeConfigSonModel getModelById(Integer id) {
        return trainTypeConfigSonMapper.selectById(id);
    }

    @Override
    public int insert(TrainTypeConfigSonModel model) {

        return trainTypeConfigSonMapper.insert(model);
    }

    @Override
    public void update(TrainTypeConfigSonModel model) {
        trainTypeConfigSonMapper.updateById(model);
    }

    @Override
    public void delete(Integer id) {
        trainTypeConfigSonMapper.deleteById(id);
    }
    @Override
    public List<TrainTypeConfigSonModel> getListByTypeIdAndTrainId(Integer trainId, Integer typeId) {
        QueryWrapper<TrainTypeConfigSonModel> queryWrapper = new QueryWrapper<>();
        if(trainId!=null&&trainId>0)
        {
            queryWrapper.eq("train_id", trainId);

        }
        if(typeId!=null&&typeId>0)
        {
            queryWrapper.eq("type_id", typeId);
        }
        List<TrainTypeConfigSonModel> conList = trainTypeConfigSonMapper.selectList(queryWrapper);
        return conList;
    }
}
